package com.google.gwt.mobile.widgets.event;

import com.google.gwt.user.client.Event;

/**
 * The Class DragEvent.
 */
public class DragEvent extends AbstractTouchEvent<DragEventHandler> {

  /**
   * The Enum DragType.
   */
  public enum DragType {
    START, MOVE, END
  };

  public static final Type<DragEventHandler> TYPE = new Type<DragEventHandler>();

  private final double _x, _y;
  private final double _offsetX, _offsetY;
  private final DragType _type;

  /**
   * Instantiates a new drag event.
   * 
   * @param nativeEvent the native event
   * @param type the type
   * @param x the x
   * @param y the y
   * @param offsetX the offset x
   * @param offsetY the offset y
   */
  public DragEvent(final Event nativeEvent, final DragType type, final double x, final double y,
      final double offsetX, final double offsetY) {
    super(nativeEvent);

    _type = type;
    _x = x;
    _y = y;
    _offsetX = offsetX;
    _offsetY = offsetY;
  }

  /*
   * (non-Javadoc)
   * 
   * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
   */
  @Override
  public Type<DragEventHandler> getAssociatedType() {
    return TYPE;
  }

  /*
   * (non-Javadoc)
   * 
   * @see
   * com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared
   * .EventHandler)
   */
  @Override
  public void dispatch(final DragEventHandler handler) {
    switch (_type) {
      case START:
        handler.onDragStart(this);
        break;
      case MOVE:
        handler.onDragMove(this);
        break;
      case END:
        handler.onDragEnd(this);
        break;
    }
  }

  /**
   * Gets the x.
   * 
   * @return the x
   */
  public double getX() {
    return this._x;
  }

  /**
   * Gets the y.
   * 
   * @return the y
   */
  public double getY() {
    return this._y;
  }

  /**
   * Gets the offset x.
   * 
   * @return the offset x
   */
  public double getOffsetX() {
    return this._offsetX;
  }

  /**
   * Gets the offset y.
   * 
   * @return the offset y
   */
  public double getOffsetY() {
    return this._offsetY;
  }
}
